<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-add">
			<div class="form-group">
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>任务名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="name" id="name" required>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">任务描述：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="remark" id="remark" >
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">所属项目：</label>
				<div class="col-sm-8">
					<select name="project.id" id="projectId" class="form-control" onchange="loadStep()" >
						<option value=''>全部</option>
                        <option th:each="project : ${projectList}" th:text="${project.name}" th:value="${project.id}" ></option>
                    </select>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">所属步骤：</label>
				<div class="col-sm-8">
					<select name="step.id" id="stepId" class="form-control" >
								
                    </select>
				</div>
			</div>
			
			
			<div class="form-group">
				<label class="col-sm-3 control-label">标签：</label>
				<div class="col-sm-8">
					<select name="label.id"  class="form-control"  >
                        <option th:each="label : ${labelList}" th:text="${label.name}" th:value="${label.id}" required></option>
                    </select>
				</div>
			</div>
			
			
			<div class="form-group">
				<label class="col-sm-3 control-label">优先级：</label>
				<div class="col-sm-8">
					<select name="yxj" class="form-control m-b" th:with="type=${@dict.getType('task_yxj')}">
	                	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	            	</select>
				</div>
			</div>
			
			
			<div class="form-group">
				<label class="col-sm-3 control-label">预计时间：</label>
				<div class="col-sm-8">
					<input type="text" data-type="datetime"  data-format="yyyy-MM-dd HH:mm:ss"  class="time-input form-control" id="endTime" name="endTime" required>
				</div>
			</div>
			
			<input name="fileList" id="fileList" type="hidden" />
			
			<div class="form-group">
				<label class="col-sm-3 control-label">上传附件：</label>
				<input type="file" name="files" multiple onchange="uploadFile()" >
			</div>
			 
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "task/task";
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-add').serialize());
	        }
	    }
		
		$("#form-add").validate({
			onkeyup: false,
			rules:{
				sort:{
					digits:true
				}
			},
			messages: {
		        
		    },
		    focusCleanup: true
		});
		
		function loadStep(){
			var projectId = $("#projectId").val();
			if(projectId == null || projectId == ''){
				$("#stepId").html("");
				return ;
			}
			$.ajax({
				url: ctx + "/task/task/loadStepByProjectId/" + projectId,
				dataType: 'json',
				type: 'post',
				success: function(data){
					var str = "";
					for(var i=0;i<data.length;i++){
						var obj = data[i];
						str += ("<option value='"+obj.id+"'>" + obj.name + "</option>")
					}
					$("#stepId").html(str);
				}
			});
		}
		
		var fileList = []
		function uploadFile(){
			var formdata = new FormData(document.getElementById("form-add"));
		    $.ajax({
		        url: prefix + "/uploadFile",
		        data: formdata,
		        type: "post",
		        processData: false,
		        contentType: false,
		        success: function(result) {
		        	fileList = fileList.concat(result.data)
		        	$("#fileList").val(JSON.stringify(fileList));
		        	console.log(JSON.stringify(fileList))
		        }
		    })
		}
		
	</script>
</body>
</html>
